/**
*      author: Y_Yao
*      created: 2024-11-09 10:36:33
**/

#include<bits/stdc++.h>

#define int LL
using namespace std;
using LL = long long;
const LL LLINF = 1e18;
const int INF = 0x3f3f3f3f;
const int N = 1000 + 7;
int a[N],b[N];
int n,v;

void solve()
{
    cin >> n >> v;
    for(int i = 1;i <= n;i++)
    {
        cin >> a[i];
    }
    for(int i = 1;i <= n;i++)
    {
        cin >> b[i];
    }
    
    vector<vector<int>> dp(n + 1,vector<int>(v + 1,0));
    for(int i = 1;i <= n;i++)
    {
        for(int j = 0;j <= v;j++)
        {
            if(b[i] > j)
            {
                dp[i][j] = dp[i-1][j];
            }
            else
            {
                dp[i][j] = max(dp[i-1][j],dp[i-1][j-b[i]] + a[i]);
            }
        }
    }

    cout << dp[n][v] << endl;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int t = 1;
    cin >> t;
    while(t--)
    {
        solve();
    }
    return 0;
}